<?php
require_once 'config.php';
require_once __DIR__ . '/includes/slug_helper.php';

 

ensureSlugs($pdo, ['categories']);

$pageTitle = "Our Services";
$pageDescription = "Buy real Instagram followers, YouTube views, TikTok likes and more. Instant delivery, best prices, 24/7 support.";
$pageKeywords    = "buy instagram followers, buy youtube views, buy tiktok likes, smm panel, social media services";
require_once 'header.php'; // Your new header



$categories = cc_remember('categories', CC_TTL_CONTENT, function () use ($pdo) {
    try {
        return $pdo->query("SELECT * FROM categories ORDER BY sort_order, name")->fetchAll(PDO::FETCH_ASSOC);
    } catch (Exception $e) {
        return [];
    }
});
?>
<h2><?php echo $pageTitle; ?></h2>
<div class="services">
    <?php if (empty($categories)): ?>
        <p>No service categories are available at this time.</p>
    <?php else: ?>
        <?php foreach ($categories as $category): ?>
            <?php
            // Use slug URL if available, fallback to id
            $catHref = !empty($category['slug'])
                ? '/' . htmlspecialchars($category['slug'])
                : '/subcategories.php?id=' . (int)$category['id'];
            ?>
            <a href="<?php echo $catHref; ?>" class="service-btn">
                <span class="service-icon">
                    <?php if (!empty($category['image_url'])): ?>
                        <?php $_img = $category['image_url']; if ($_img && $_img[0] !== '/' && !preg_match('#^https?://#', $_img)) $_img = '/' . ltrim($_img, '/'); ?>
                        <img src="<?php echo htmlspecialchars($_img); ?>" alt="<?php echo htmlspecialchars($category['name']); ?>" style="width:clamp(30px,8vw,40px);height:clamp(30px,8vw,40px);object-fit:contain;border-radius:6px;display:block;vertical-align:middle;">
                    <?php else: ?>
                        <i class="<?php echo htmlspecialchars($category['icon_class']); ?>"></i>
                    <?php endif; ?>
                </span>
                <span class="service-name"><?php echo htmlspecialchars($category['name']); ?></span>
            </a>
        <?php endforeach; ?>
    <?php endif; // Render homepage-only custom code from admin integrations
$_hp_code = cc_remember('hp_code', CC_TTL_CONTENT, function () use ($pdo) {
    try {
        if (isset($pdo)) {
            $_hp_stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = ? LIMIT 1");
            $_hp_stmt->execute(['homepage_header_code']);
            return ['v' => (string)($_hp_stmt->fetchColumn() ?: '')];
        }
    } catch (Exception $e) {}
    return ['v' => ''];
})['v'] ?? '';
if ($_hp_code) {
    echo "\n<!-- Homepage Only Code -->\n";
    echo $_hp_code;
    echo "\n<!-- /Homepage Only Code -->\n";
}
?>
</div>
<br><br><br><br><br>